package com.zcxy.web.controller.edu;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zcxy.common.annotation.Log;
import com.zcxy.common.core.controller.BaseController;
import com.zcxy.common.core.domain.AjaxResult;
import com.zcxy.common.enums.BusinessType;
import com.zcxy.edu.domain.EduOrg;
import com.zcxy.edu.service.IEduOrgService;
import com.zcxy.common.utils.poi.ExcelUtil;
import com.zcxy.common.core.page.TableDataInfo;

/**
 * 院系组织Controller
 *
 * @author ruoyi
 * @date 2024-10-20
 */
@RestController
@RequestMapping("/edu/org")
public class EduOrgController extends BaseController
{
    @Autowired
    private IEduOrgService eduOrgService;

    /**
     * 查询院系组织列表
     */
    @PreAuthorize("@ss.hasPermi('edu:org:list')")
    @GetMapping("/list")
    public TableDataInfo list(EduOrg eduOrg)
    {
        startPage();
        List<EduOrg> list = eduOrgService.selectEduOrgList(eduOrg);
        return getDataTable(list);
    }

    @GetMapping("/getTreeData")
    public List<Map<String,Object>> getTreeData()
    {
        return eduOrgService.getTreeData();
    }

    /**
     * 导出院系组织列表
     */
    @PreAuthorize("@ss.hasPermi('edu:org:export')")
    @Log(title = "院系组织", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EduOrg eduOrg)
    {
        List<EduOrg> list = eduOrgService.selectEduOrgList(eduOrg);
        ExcelUtil<EduOrg> util = new ExcelUtil<EduOrg>(EduOrg.class);
        util.exportExcel(response, list, "院系组织数据");
    }

    /**
     * 获取院系组织详细信息
     */
    @PreAuthorize("@ss.hasPermi('edu:org:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eduOrgService.selectEduOrgById(id));
    }

    /**
     * 新增院系组织
     */
    @PreAuthorize("@ss.hasPermi('edu:org:add')")
    @Log(title = "院系组织", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EduOrg eduOrg)
    {
        return toAjax(eduOrgService.insertEduOrg(eduOrg));
    }

    /**
     * 修改院系组织
     */
    @PreAuthorize("@ss.hasPermi('edu:org:edit')")
    @Log(title = "院系组织", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EduOrg eduOrg)
    {
        return toAjax(eduOrgService.updateEduOrg(eduOrg));
    }

    /**
     * 删除院系组织
     */
    @PreAuthorize("@ss.hasPermi('edu:org:remove')")
    @Log(title = "院系组织", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eduOrgService.deleteEduOrgByIds(ids));
    }
}
